package com.book.helper;

import com.book.dto.BookDto;
import com.book.pojo.Book;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * @Author 李锦程
 * @Date 2021/4/2 3:38 下午
 * @Package com.book.helper
 * @Version 1.0
 */
public class UBookHelper {
    public static BookDto covertPoDto(Book uBook) {
        if (uBook == null){
            return null;
        }
        BookDto uBookDto = new BookDto();
        BeanUtils.copyProperties(uBook, uBookDto);
        return uBookDto;
    }

    public static List<BookDto> covertList(List<Book> list) {
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        List<BookDto> listDto = Lists.newArrayList();
        for (Book u : list
        ) {
            BookDto uBookDto = covertPoDto(u);
            listDto.add(uBookDto);
        }
        return listDto;
    }

    public static Book covertDtpPO(BookDto uBookDto) {
        if (uBookDto != null) {
            Book uBook = new Book();
            BeanUtils.copyProperties(uBookDto, uBook);
            return uBook;
        }
        return null;
    }
}
